<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>点美优校管理平台</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">教学管理</a>
        <a>
          <cite>部门信息</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="hidden" id="totalPageAllAppoint" name="totalPageAllAppoint">
            <input type="hidden" id="departmentEditPermission" name="departmentEditPermission"
                   value="${departmentEditPermission!}">
            <input type="hidden" id="departmentDeletePermission" name="departmentDeletePermission"
                   value="${departmentDeletePermission!}">
        <#--<input class="layui-input" placeholder="开始日" name="start" id="start">-->
        <#--<input class="layui-input" placeholder="截止日" name="end" id="end">-->
        <#--<div class="layui-input-inline">-->
        <#--<select name="gradeId" id="gradeId" lay-filter="gradeId">-->
        <#--&lt;#&ndash;<option value=""></option>&ndash;&gt;-->
        <#--&lt;#&ndash;<#list gradeList as grade>&ndash;&gt;-->
        <#--&lt;#&ndash;<option value="${grade.pl_value}">${grade.pl_name}</option>&ndash;&gt;-->
        <#--&lt;#&ndash;</#list>&ndash;&gt;-->
        <#--</select>-->
        <#--</div>-->
        <#--<div class="layui-input-inline">-->
        <#--<select name="classId" id="classId" lay-filter="classId">-->

        <#--</select>-->
        <#--</div>-->
            <input type="text" name="name" id="name" placeholder="请输入部门名称" autocomplete="off" class="layui-input">
            <button class="layui-btn" lay-submit="" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock <#if departmentEditPermission??> <#else>style="display: none"</#if>>
        <button class="layui-btn layui-btn-danger" onclick="x_admin_show('批量添加部门','/system/departmentBatchAdd',600,400)"
        ><i class="layui-icon"></i>批量导入
        </button>
        <button class="layui-btn" onclick="x_admin_show('添加部门','/system/departmentAdd',600,400)"><i
                class="layui-icon"></i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<font id="total"></font> 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
        <#--<th>-->
        <#--<div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i-->
        <#--class="layui-icon">&#xe605;</i></div>-->
        <#--</th>-->
        <#--<th>ID</th>-->

            <th>ID</th>
            <th>部门名称</th>
            <th>部门简称</th>
            <th>部门描述</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="tbody">

        </tbody>
    </table>
    <div class="page" id="data">

    </div>

</div>
<script>


    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                url: "/{{class_name}}/delete/" + id,
                type: 'post',
                data: {_method: "DELETE"},
                cache: true,
                success: function (data) {
                    layer.msg('删除成功', {icon: 1});
                    $(obj).parents("tr").remove();
                },
                complete: function () {
                }
            });
        });

    }

    function reloadData() {
        //刷新表格数据
        getData(page);
    }

    var page = 1;
    var pageSize = 10;
    var totalPageAllAppoint = 10;

    function getData(nowPage) {
        var classId = $("#classId").val();
        var gradeId = $("#gradeId").val();
        var name = $("#name").val().trim();
        $.ajax({
            url: "/{{class_name}}/list/" + nowPage + "/" + pageSize + "/1",
            type: 'get',
            data: {gradeId: gradeId, classId: classId, name: name},
            cache: true,
            success: function (data) {
                console.log(data);
                var content = "";
                if (data) {
                    $("#total").text(data.total);
                    $("#totalPageAllAppoint").val(data.total);
                    totalPageAllAppoint = data.total;
                    var tData = data.list;
                    for (var i = 0; i < tData.length; i++) {
                        var td_data = tData[i];
                        var sexKey = td_data.sex;

                        var address = "";
                        if (td_data.address) {
                            address = td_data.address;
                        }
                        var departmentEdit = "";
                        var departmentEditPermission = $("#departmentEditPermission").val();
                        if (departmentEditPermission != null && departmentEditPermission != '') {
                            departmentEdit = "                <a title=\"编辑\" onclick=\"x_admin_show('编辑','/system/departmentEdit/" + td_data.id + "',600,400)\" href=\"javascript:;\">\n" +
                                    "                    <i class=\"layui-icon\">&#xe642;</i>\n" +
                                    "                </a>\n";
                        }

                        var departmentDelete = "";
                        var departmentDeletePermission = $("#departmentDeletePermission").val();
                        if (departmentDeletePermission != null && departmentDeletePermission != '') {
                            departmentDelete = "                <a title=\"删除\" onclick=\"member_del(this,'" + td_data.id + "')\" href=\"javascript:;\">\n" +
                                    "                    <i class=\"layui-icon\">&#xe640;</i>\n" +
                                    "                </a>\n";
                        }


                        var simpleName = "";
                        if (td_data.simpleName != null) {
                            simpleName = td_data.simpleName;
                        }
                        var detail = "";
                        if (td_data.detail != null) {
                            detail = td_data.detail;
                        }
                        content += "  <tr>\n" +
                                // "            <td>\n" +
                                // "                <div class=\"layui-unselect layui-form-checkbox\" lay-skin=\"primary\" data-id='2'><i class=\"layui-icon\">&#xe605;</i>\n" +
                                // "                </div>\n" +
                                // "            </td>\n" +
                                // "            <td>"+td_data.id+"</td>\n" +

                                "            <td>" + td_data.id + "</td>\n" +
                                "            <td>" + td_data.name + "</td>\n" +
                                "            <td>" + simpleName + "</td>\n" +
                                "            <td>" + detail + "</td>\n" +
                                "            <td class=\"td-manage\">\n" +
                                departmentEdit + departmentDelete +
                                "            </td>\n" +
                                "        </tr>";
                    }

                }
                $("#tbody").html("");
                $("#tbody").append(content);
            },
            complete: function () {
                layui.use('laypage', function (data) {
                    var laypage = layui.laypage;
                    //调用分页
                    // getData(page);

                    laypage.render({
                        elem: 'data'
                        , count: $("#totalPageAllAppoint").val()
                        , first: '首页'
                        , last: '尾页'
                        , prev: '<em>←</em>'
                        , next: '<em>→</em>'
                        , curr: page
                        , jump: function (obj, first) {
                            //渲染
                            if (!first) {
                                page = obj.curr;
                                getData(obj.curr);

                            } else {
                            }

                        }
                    });
                });

            },
        });
    }

    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
                , layer = layui.layer;
        //监听提交
        form.on('submit(search)', function (data) {
            getData(page);
            return false;

        });
    });
    $(function () {
        getData(page);
    })
</script>
</body>

</html>